#include <stdio.h>
#define MAX_ROW 9
#define MAX_COL 9
void print_maze(char array[][MAX_COL])
{
	int i, j;
	for (i = 0; i < MAX_ROW; i++){
		for (j = 0; j < MAX_COL; j++) {
			printf("%d ", array[i][j]);
		}
		printf("\n");
	}
}
int visit(char array[][MAX_COL], int row, int col)
{
	if (row == 0 && col == 0){
		printf("(%d, %d)\n", row, col);
		return 0;
	} 
	if (row < 0 || row >= MAX_ROW) return -1;
	if (col < 0 || col >= MAX_COL) return -1;

	if (array[row][col] == 0 || array[row][col] == 2) return -1;

	array[row][col] = 2;
	if (visit(array, row - 1, col) == 0) {
		printf("(%d, %d)\n", row, col);
		return 0;
	}
	if (visit(array, row, col-1) == 0) {
		printf("(%d, %d)\n", row, col);
		return 0;
	}
	if (visit(array, row + 1, col) == 0) {
		printf("(%d, %d)\n", row, col);
		return 0;
	}
	if (visit(array, row, col + 1) == 0) {
		printf("(%d, %d)\n", row, col);
		return 0;
	}
	return -1;
}

int main(void)
{
	char array[MAX_ROW][MAX_COL] = {
	{1, 0, 0, 0, 0, 0, 0, 0, 0},
	{1, 1, 0, 0, 0, 0, 0, 0, 0},
	{0, 1, 0, 0, 0, 0, 0, 0, 0},
	{0, 1, 0, 0, 1, 0, 0, 0, 0},
	{0, 1, 1, 0, 1, 1, 1, 0, 0},
	{0, 0, 1, 0, 1, 0, 1, 0, 0},
	{0, 0, 1, 1, 1, 0, 1, 0, 0},
	{0, 0, 0, 0, 0, 0, 1, 1, 0},
	{0, 0, 0, 0, 0, 0, 0, 1, 1},
	};
	print_maze(array);
	visit(array, MAX_ROW-1, MAX_COL-1);
	print_maze(array);
	return 0;
}
